﻿using DotNetCommon;
using Furion;
using Furion.FriendlyException;
using Masuit.Tools.Systems;
using Snowflake.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace furion.blog.Utils
{
    public class IdUtil
    {
        static string? workerId = null;
        static string? datacenterId = null;

        static IdUtil()
        {
            workerId = App.Configuration["AppInfo:WorkerId"];
            datacenterId = App.Configuration["AppInfo:DataCenterId"];
            if (string.IsNullOrEmpty(workerId))
            {
                throw Oops.Oh($"App WorkerId 未配置");
            }
            if (string.IsNullOrEmpty(datacenterId))
            {
                throw Oops.Oh($"App DataCenterId 未配置");
            }
            //workerId = long.Parse(wid);
            //datacenterId = long.Parse(did);
        }

        public static long Id()
        {
           
            //var worker = new IdWorker(workerId,datacenterId);
            //return worker.NextId();
            return DistributeGenerator.NewId(workerId);
        }

        /// <summary>
        /// 返回短id字符串
        /// </summary>
        /// <returns></returns>
        public static string ShortId() {
            var sf = SnowFlake.GetInstance();
            return sf.GetUniqueShortId();
        }

    }
}
